﻿using System;
using Newtonsoft.Json;

namespace OrkutAPILibrary.Entities
{
    /// <summary>
    /// Orkut Access Control
    /// </summary>
    [JsonObject()]
    public class OrkutAccessControl
    {
        /// <summary>
        /// Gets or sets the entries.
        /// </summary>
        /// <value>The entries.</value>
        [JsonProperty(PropertyName = "entries")]
        public OrkutAccessControlEntries[] Entries { get; set; }
    }

    public class OrkutAccessControlEntries
    {
        private static readonly DateTime unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

        /// <summary>
        /// Gets or sets the accessor info.
        /// </summary>
        /// <value>The accessor info.</value>
        [JsonProperty(PropertyName = "accessorInfo")]
        public string AccessorInfo { get; set; }

        /// <summary>
        /// Gets or sets the type of the accessor.
        /// </summary>
        /// <value>The type of the accessor.</value>
        [JsonProperty(PropertyName = "accessorType")]
        public string AccessorType { get; set; }

        /// <summary>
        /// Gets or sets the creation time.
        /// </summary>
        /// <value>The creation time.</value>
        public DateTime CreationTime { get; set; }

        [JsonProperty(PropertyName = "creationTime")]
        private string _creationTime
        {
            get
            {
                return (CreationTime - unixEpoch).TotalSeconds.ToString();
            }
            set
            {
                CreationTime = unixEpoch.AddSeconds(Convert.ToInt32(value));
            }
        }

        /// <summary>
        /// Gets or sets the accessor id.
        /// </summary>
        /// <value>The accessor id.</value>
        [JsonProperty(PropertyName = "accessorId")]
        public string AccessorId { get; set; }

        /// <summary>
        /// Gets or sets the type of the access.
        /// </summary>
        /// <value>The type of the access.</value>
        [JsonProperty(PropertyName = "accessType")]
        public string AccessType { get; set; }
    }
}
